'use strict';

const Service = require('egg').Service;
class AdvertisementService extends Service {

  async getall(){
    const result = {}
    try {
        const uid = await this.app.mysql.select('table_gg');
        result.code = 200,
        result.message = '获取成功!'
        result.data_list = uid
    } catch (error) {
        result.code = 201,
        result.message = error.message
    }
    return result
  }
  async add(data){
    const result = {}
    try {
        const uid = await this.app.mysql.insert('table_gg',data);
        if(uid.affectedRows===1){
            result.code = 200,
            result.message = '添加成功!'
            result.insertId = uid.insertId
        }else{
            result.code = 201,
            result.message = uid.message
        }

    } catch (error) {
        result.code = 202,
        result.message = error.message
    }
    return result
  }
  async update(data){
    const result = {}
    try {
        const uid = await this.app.mysql.update('table_gg', data)
        if(uid.affectedRows===1){
            result.code = 200,
            result.message = '修改成功!'
        }else{
            result.code = 201,
            result.message = uid.message
        }

    } catch (error) {
        result.code = 202,
        result.message = error.message
    }
    return result
  }
  async delete(data){
    const result = {}
    try {
        const uid = await this.app.mysql.delete('table_gg', {id:data.id})
        result.code = 200,
        result.message = '删除成功!'
    } catch (error) {
        result.code = 201,
        result.message = error.message
    }
    return result
  }
}

module.exports = AdvertisementService;